
import re

def find_space_test():
    text = "foo    bar\t baz \tqux"
    result = re.split('\s+', text)
    print(result)
    regex = re.compile('\s+')
    result = regex.split(text)
    print(result)
    print(regex.findall(text))


def find_email():
    text = """Dave dave@google.com
Steve steve@gmail.com
Rob rob@gmail.com
Ryan ryan@yahoo.com
    """
    pattern = r'[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'
    # re.IGNORECASE makes the regex case-insensitive
    regex = re.compile(pattern, flags=re.IGNORECASE)
    print(regex.findall(text))
    m = regex.search(text)
    print(m)
    print(text[m.start():m.end()])
    print(regex.match(text))         # from start
    print(regex.sub('REDACTED', text))

def match_test():
    text = """Dave dave@google.com
    Steve steve@gmail.com
    Rob rob@gmail.com
    Ryan ryan@yahoo.com
    """
    pattern = r'([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})'
    regex = re.compile(pattern, flags=re.IGNORECASE)
    m = regex.match('wesm@bright.net')
    print(m.groups())
    print(regex.findall(text))
    print(regex.sub(r'Username: \1, Domain: \2, Suffix: \3', text))



if __name__ == '__main__':
    # find_email()
    match_test()
